package com.jeesite.modules.dataScreen.utils;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;

public class MyDateUtils {

    /**
     * 获取当天的开始和结束时间
     *
     * @return [开始时间, 结束时间]
     */
    public static DateTime[] getCurrentDay() {
        return new DateTime[]{DateUtil.beginOfDay(DateUtil.offsetDay(DateUtil.date(), 0)), DateUtil.endOfDay(DateUtil.offsetDay(DateUtil.date(), 0))};
    }

    public static DateTime[] lately(String offsetStr) {
        DateTime endTime = DateUtil.date();
        DateTime startTime;
        switch (offsetStr) {
            case "年":
                startTime = DateUtil.offsetMonth(endTime, -12);
                break;
            case "季":
                startTime = DateUtil.offsetMonth(endTime, -3);
                break;
            case "月":
                startTime = DateUtil.offsetMonth(endTime, -1);
                break;
            case "周":
                startTime = DateUtil.offsetDay(endTime, -7);
                break;
            case "今日":
                startTime = DateUtil.beginOfDay(endTime);
                break;
            default:
                throw new RuntimeException("不支持的offsetStr：" + offsetStr);
        }
        return new DateTime[]{startTime, endTime};
    }
}
